package appli.calcul;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

public class Map extends MapActivity{

	private MapView mapView;
	private MapController mc;
	private GeoPoint location;
	private Button recherche;
	private Button itineraire;
	private Button option;
	private static final int CODE_RET_REC = 1;
	private static final int CODE_RET_IT = 2;
	private static final int CODE_RET_OPT = 3;
	
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.map);

		mapView = (MapView) findViewById(R.id.mapView);
		recherche = (Button) findViewById(R.id.buttonrec);
		itineraire = (Button) findViewById(R.id.buttonit);
		option = (Button) findViewById(R.id.buttonopt);

		mapView.setBuiltInZoomControls(true);
		this.mc = this.mapView.getController();
		double latitude = 47.84;
		double longitude = 1.93;
		this.location = new GeoPoint((int) (latitude * 1000000.0),(int) (longitude * 1000000.0));
		this.mc.setCenter(this.location);
		this.mc.setZoom(15);
		this.mapView.setSatellite(true);
		this.mapView.invalidate();

		final Activity act = this;

		recherche.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent page = new Intent(act, Recherche.class);
				page.putExtra("iti", false);
				act.startActivityForResult(page, CODE_RET_REC);
			}
		});

		itineraire.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent iti = new Intent(act, Itineraire.class);

				act.startActivityForResult(iti, CODE_RET_IT);
			}
		});
		
		option.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent opt = new Intent(act, options.class);

				act.startActivityForResult(opt, CODE_RET_OPT);
			}
		});

	}

	public GeoPoint getLocation() {
		return location;
	}

	public void setLocation(GeoPoint location) {
		this.location = location;
		this.mc.setCenter(this.location);
		this.mapView.invalidate();
	}

	@Override
	protected boolean isRouteDisplayed() {
		return true;
	}

	protected void onActivityResult(int ident, int code_retour, Intent retour)
	{
		switch(ident)
		{
			case CODE_RET_IT : return;
			
			case CODE_RET_REC : return;
			
			case CODE_RET_OPT : return;
		}
	}
	
}

